|
|
 |
|
|
|
|
' Create a rotation matrix for rotating through
' angle theta around the point (x, y). Public Sub m2RotateAround(Result() As Single, _
ByVal theta As Single, _
ByVal x As Single, ByVal y As Single)
Dim T(1 To 3, 1 To 3) As Single
Dim R(1 To 3, 1 To 3) As Single
Dim T_Inv(1 To 3, 1 To 3) As Single
Dim M(1 To 3, 1 To 3) As Single
' Translate the point to the origin. m2Translate T, -x, -y
' Compute the inverse translation. m2Translate T_Inv, x, y
' Rotate. m2Rotate R, Theta
' Combine the transformations. m2MatMultiply M, T, R
m2MatMultiply Result, M, T_Inv
End Sub |
|
|
|
|
|
|
|
|
You can find the routines described in this section, along with other routines that manipulate two-dimensional transformation matrices, in the file M2Ops.bas. Example programs ScaleAt, ReflAt, and RotAt demonstrate the m2ScaleAt, m2ReflectAcross, and m2RotateAround subroutines respectively. |
|
|
|
|
|
|
|
|
Program ScaleAt draws a square. When you click on the Big, Normal, and Little option buttons, the program uses subroutine m2ScaleAt to scale the square around its center by a factor of 2, 1, or 1/2 respectively. |
|
|
|
|
|
|
|
|
Program ReflAt draws a square and a line. When you check the Reflect box, the program uses subroutine m2ReflectAcross to reflect the square across the line. When you uncheck this box, the program places the square back in its original position. |
|
|
|
|
|
|
|
|
Program RotAt also draws a square. When you press the right arrow key, the program uses subroutine m3RotateAround to rotate the square clockwise around its center. When you press the left arrow key, the program uses m3RotateAround to rotate the square counterclockwise. |
|
|
|
|
|
|
|
|
Vector and Matrix Operations in Visual Basic |
|
|
|
|
|
|
|
|
Whenever you multiply two matrices that both have 0, 0, 1 in the final column, you get another matrix with 0, 0, 1 in the final column. No matter how you compose translation, scaling, and rotation matrices, the resulting matrix will always have the form: |
|
|
|
|
|